package com.tan.api.controller.user;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.tan.common.dto.user.MenuCreateDTO;
import com.tan.common.dto.user.MenuUpdateDTO;
import com.tan.common.query.user.MenuQuery;
import com.tan.common.vo.Option;
import com.tan.common.vo.user.MenuVO;
import com.tan.common.vo.user.RouteVO;
import com.tan.core.response.ApiResponse;
import com.tan.user.service.ISysMenuService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 菜单
 * </p>
 *
 * @author Tan
 * @since 2025-01-27
 */
@RestController
@RequestMapping("/sys/menu")
public class SysMenuController {

    @Resource
    private ISysMenuService menuService;

    @GetMapping("/routes")
    public ApiResponse<List<RouteVO>> routes() {
        return ApiResponse.success(menuService.listRoutes());
    }


    @GetMapping("/pages")
    public ApiResponse<IPage<MenuVO>> pages(MenuQuery menuQuery) {
        return ApiResponse.success(menuService.menuPages(menuQuery));
    }


    @GetMapping("/options")
    public ApiResponse<List<Option>> options() {
        return ApiResponse.success(menuService.menuOptions());
    }

    @PostMapping("/create")
    public ApiResponse<Void> create(@RequestBody MenuCreateDTO createDTO) {
        menuService.createMenu(createDTO);
        return ApiResponse.success();
    }

    @PostMapping("/update")
    public ApiResponse<Void> update(@RequestBody MenuUpdateDTO menuUpdateDTO) {
        menuService.updateMenu(menuUpdateDTO);
        return ApiResponse.success();
    }

    @PostMapping("/del/{menuId}")
    public ApiResponse<Void> del(@PathVariable("menuId") Long menuId) {
        menuService.delMenu(menuId);
        return ApiResponse.success();
    }

}
